<template>
  <div class="wrapper">
    <ul>
      <router-link tag="li" :to="'/help'">
        <span class="iconfont icon-bangzhufankui"></span>
        帮助与反馈
        <span class="iconfont icon-gengduo"></span>
      </router-link>
      <router-link tag="li" :to="'/about'">
        <span class="iconfont icon-guanyuwomen"></span>
        关于我们
        <span class="iconfont icon-gengduo"></span>
      </router-link>
      <li @click="logOut" v-show="is_out">
        <span class="iconfont icon-tuichudenglu"></span>
        退出登录
        <span class="iconfont icon-gengduo"></span>
      </li>
    </ul>
  </div>
</template>

<script>
import { mapMutations } from 'vuex'
export default {
  name: 'CompanyList',
  data () {
    return {
      is_out: false
    }
  },
  beforeMount () {
    if (sessionStorage.getItem('token')) {
      this.is_out = true
    } else {
      this.is_out = false
    }
  },
  methods: {
    ...mapMutations(['changeLogin']),
    ...mapMutations(['changeUName']),
    ...mapMutations(['changeUid']),
    ...mapMutations(['changeUavatar']),
    logOut () {
      this.$dialog.confirm({
        title: '您确定要退出登录吗'
      }).then(() => {
        this.$axios.get(process.env.API_HOST + '/api/user/logout')
          .then(this.logOutSee)
          .catch(error => console.log(error))
      }).catch(() => {
      })
    },
    logOutSee (res) {
      if (res.data.code === 1) {
        this.changeLogin({ token: '' })
        this.changeUName({ name: '' })
        this.changeUid({ id: '' })
        this.changeUavatar({ avatar: '' })
        this.$toast('退出成功')
        setTimeout(function () {
          location.reload()
        }, 1500)
      }
    }
  }
}
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="stylus" scoped>
.wrapper
  background #fff
  ul
    width 90%
    margin-left 5%
    margin-right 5%
    li
      height 1.16rem /* 58/50 */
      line-height 1.16rem /* 58/50 */
      border-top 1px solid rgba(0,0,0,.1)
      .icon-bangzhufankui
        color #FF8400
        font-size .34rem /* 17/50 */
      .icon-guanyuwomen
        color #0097E5
        font-size .34rem /* 17/50 */
      .icon-tuichudenglu
        color #FF3000
        font-size .34rem /* 17/50 */
      .icon-gengduo
        float right
        font-size .26rem /* 13/50 */
        color #999999
    li:nth-child(1)
        border 0px
</style>
